function refresh(){
    $("#dataTable").bootstrapTable("removeAll");
    $("#dataTable").bootstrapTable('refresh');
}
function yesOperator(){
    console.log("====yesOperator=====");
    var retValue=selectData();
    return retValue;
}
function selectData(){

    var len = $("#dataTable input:checked").length;

    if (len == 0) {
        //未选中数据提示框
        layer.msg('请选择数据',  {time:2500});

    } else {

        var rows= $("#dataTable").bootstrapTable('getSelections');
        var rowIds = [];
        var ret={};
        return rows[0];
    }
}
//搜索以前将页码换成第一页
function searchInit(){
    var options=$("#dataTable").bootstrapTable("getOptions");
    options.pageNumber=1;
    $("#dataTable").bootstrapTable('refreshOptions',options);
}

$(function () {
    $("#serachBtn").click(function(){
        searchInit();
        refresh();
    });
    $('#serachBtn').bind('keypress',function(e){
        searchInit();

        if(e.keyCode == 13){
            refresh();
        }
    });

    $('#samplingCode').bind('keypress',function(e){


        if(e.keyCode == 13){
            searchInit();
            refresh();
        }
    });
    $('#samplingName').bind('keypress',function(e){


        if(e.keyCode == 13){
            searchInit();
            refresh();
        }
    });

    $("#searchCondition").focus();
    //渲染表格
    var columns = samplingRuleList.columnsInit();
    var table = samplingRuleList.gridInit(columns);
    var datas = samplingRuleList.dataInit();
    $("#dataTable").bootstrapTable("append",datas);
})
;(function(undefined) {
    "use strict"
    var _global;

    function result(args,fn){
        var argsArr = Array.prototype.slice.call(args);
        if(argsArr.length > 0){
            return argsArr.reduce(fn);
        } else {
            return 0;
        }
    }
    var samplingRuleList = {
        columnsInit:function(){
            return  [{
                field: 'radio',
                radio: true,
                align: 'center',
                valign: 'middle'
            },{
                field: 'status',
                title: '序号',
                formatter: function (value, row, index) {
                    return     index+1 ;
                }
            },
                {field:"samplingCode",title:"采样编码" },
                {field:"samplingName",title:"采样名称" },
                {field:"samplingCycle",title:"采样周期" },
                {field:"status",title:"状态" },
                {field:"rowSort",title:"排序号" },
                {field:"remarks",title:"备注" },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        if(value == '1'){
                            return [
                                '<span class="sys-type-bg pro-status-green">正常</span>'
                            ];
                        }
                        return [
                            '<span class="sys-type-bg pro-status-red">停用</span>'
                        ];
                    }
                }]
        },
        gridInit:function(columns){
            return $("#dataTable").bootstrapTable({
                method:"post",
                contentType:"application/x-www-form-urlencoded",
                url:$$.restServerUrl+'/bootstrap/basegrid/IotSamplingBusiness/list',
                columns: columns,
                undefinedText:'-',
                striped: 'true',
                classes: 'table table-hover qxttable',
                pagination: 'true',
                clickToSelect: true,
                singleSelect:false,
                sidePagination: "server",
                queryParamsType : "page",
                sortSide:'client',
                sortable:true,
                pageNumber: 1,
                pageSize:10,
                idField:'id',
                silentSort: true,
                pageList: [
                	10, 20, 50, 100
                ],
                onClickRow:function(row, $element,field){
                    $("#dataTable").bootstrapTable("uncheckAll");
                },
                queryParams: function queryParams(params) {   //设置查询参数

                    var args={};
                    args.c_samplingCode_7=$("#samplingCode").val();
                    args.c_samplingName_7=$("#samplingName").val();
                    args.page=params.pageNumber-1; //    params.pageNumber
                    args.pageSize=params.pageSize;     //params.pageSize
                    args.isPage=1;
                    //args.order=orderStr;
                    var paramStr=JSON.stringify(args);

                    //alert(params.pageNumber+":"+params.pageSize);
                    //alert(orderStr);
                    var param = {
                        params:paramStr
                    };
                    return param;
                }
            })

        },
        dataInit:function(){
            return  []
        }
    }

    // 将插件对象暴露给全局对象
    _global = (function(){ return this || (0, eval)('this'); }());
    if (typeof module !== "undefined" && module.exports) {
        module.exports = samplingRuleList;
    } else if (typeof define === "function" && define.amd) {
        define(function(){return samplingRuleList;});
    } else {
        !('plugin' in _global) && (_global.samplingRuleList = samplingRuleList);
    }
}());